package cn.chencaiju.service;

import java.util.List;

import org.elasticsearch.index.query.QueryBuilder;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.index.query.TermQueryBuilder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.chencaiju.dao.ProductDao;
import cn.chencaiju.domain.Product;

@Service
public class ProductService {
	@Autowired
	ProductDao dao;
	
	//根据名字商品精准查询，
	public Iterable<Product> searchProdtByName(String name){
		QueryBuilder qb = QueryBuilders.termQuery("name",name);
		System.out.println(qb);
		Iterable<Product> list = dao.search(qb);
		return list;
	}
	//根据商品分类名称精准查询
	public Iterable<Product> searchByCateName(String cateName) {
		TermQueryBuilder query = QueryBuilders.termQuery("catelogName", cateName);
		Iterable<Product> iterable = dao.search(query);
		return iterable;
	}
	//根据价格区间查询
	public List<Product> searchByPrice(Double p1,Double p2) {
		return dao.findByPriceBetween(p1, p2);
	}
}
